<?php

defined('IN_IA') or exit('Access Denied');

$dos = array('display', 'post', 'list', 'del','query');
$do = !empty($_GPC['do']) && in_array($do, $dos) ? $do : 'list';
$device = getDevices();
if ($do == 'list') {

    $_W['page']['title'] = '管理短信接收人 - 接收人列表';
    $status=getGeneStatus();
    $sendee = trim($_GPC['sendee']);
    $mobile = trim($_GPC['mobile']);
    $wheresql = " WHERE 1 ";
    if (!empty($mobile)) {
        $wheresql .= " AND mobile LIKE '%{$mobile}%'";
        $_GET['mobile'] = $mobile;
    }
    if (!empty($sendee)) {
        $wheresql .= " AND name LIKE '%{$sendee}%'";
        $_GET['sendee'] = $sendee;
    }

    $pindex = max(1, intval($_GPC['page']));
    $psize = 20; //ORDER BY createtime DESC
    $list = pdo_fetchall("SELECT * FROM " . tablename('sms_sendee') . $wheresql . '   LIMIT ' . ($pindex - 1) * $psize . ',' . $psize);
    template('sms/sendee_list');
}
if ($do == 'post') {
    $_W['page']['title'] = '管理短信接收人 - 增加接收人';
    $id = intval($_GPC['id']);
    if (checksubmit('submit')) {
        $data = array(
            'name' => $_GPC['sendee'],
            'mobile' => $_GPC['mobile'],
            'worktitle' => $_GPC['worktitle'],
            'device' =>intval($_GPC['messege']),
            'status'=>intval($_GPC['status']),
        );
        if (empty($id)) {
            $data['createtime'] = TIMESTAMP;
            pdo_insert('sms_sendee', $data);
        } else {
            pdo_update('sms_sendee', $data, array('id' => $id));
        }
        message('数据更新成功！', url('sms/sendee/list'), 'success');
    }
    if (empty($id)) {
        $row=array('status'=>1);
    }else{
        $row = pdo_fetch("SELECT * FROM " . tablename('sms_sendee') . " WHERE   id = '{$id}'");
    }
    template('sms/sendee_post');
}
if ($do == 'del') {
    $id = intval($_GPC['id']);
    if($id>0){
        pdo_delete('sms_sendee',array('id' => $id));
        message('数据删除成功！', url('sms/sendee/list'), 'success');
    }
}
if ($do == 'query') {
    $ids = empty($_GPC['ids']) ? array() : $_GPC['ids'];
    $selects = getAllSendee(true);
    $ids =explode( ',',$_GPC['ids']);
    if (is_array($ids) && count($ids) > 0) {
        foreach ($selects as $k => $v) {
            if (in_array($k, $ids)) {
                unset($selects[$k]);
            }
        }
    }
    template('sms/group_query');
}